using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using SFS.SampleApp.Web.Mvc.Resources;
using System.Runtime.Serialization;
using SFSdotNet.Framework.Web.Mvc.Models;
using SFSdotNet.Framework.Web.Mvc.Extensions;
using BO = SFS.SampleApp.BusinessObjects;
using System.Web.Mvc;
using SFSdotNet.Framework.Web.Mvc.Validation;
using SFSdotNet.Framework.Web.Mvc.Models;
using SFSdotNet.Framework.Web.Mvc.Resources;
using SFSdotNet.Framework.Entities.Metadata;


namespace SFS.SampleApp.Web.Mvc.Models.Customers 
{
	public partial class CustomerModel: ModelBase{
		public CustomerModel()
        {
		}
		public override string Id
        {
            get
            {
                return this.CustomerID.ToString();
            }
        }
			
			
        public override string ToString()
        {
			if (this.Title != null)
		
            return this.Title.ToString();
			else
				return "";
		
        }    
			
	
		[SystemProperty()]		
		public Int32? CustomerID{ get; set; }
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_NAMESTYLE_REQUIRED", ErrorMessageResourceType=typeof(CustomerResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("NAMESTYLE", NameResourceType=typeof(CustomerResources))]
	public Boolean   NameStyle { get; set; }
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[LocalizedDisplayName("TITLE", NameResourceType=typeof(CustomerResources))]
	public String   Title { get; set; }
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_FIRSTNAME_REQUIRED", ErrorMessageResourceType=typeof(CustomerResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("FIRSTNAME", NameResourceType=typeof(CustomerResources))]
	public String   FirstName { get; set; }
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[LocalizedDisplayName("MIDDLENAME", NameResourceType=typeof(CustomerResources))]
	public String   MiddleName { get; set; }
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_LASTNAME_REQUIRED", ErrorMessageResourceType=typeof(CustomerResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("LASTNAME", NameResourceType=typeof(CustomerResources))]
	public String   LastName { get; set; }
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[LocalizedDisplayName("SUFFIX", NameResourceType=typeof(CustomerResources))]
	public String   Suffix { get; set; }
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[LocalizedDisplayName("COMPANYNAME", NameResourceType=typeof(CustomerResources))]
	public String   CompanyName { get; set; }
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[LocalizedDisplayName("SALESPERSON", NameResourceType=typeof(CustomerResources))]
	public String   SalesPerson { get; set; }
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[LocalizedDisplayName("EMAILADDRESS", NameResourceType=typeof(CustomerResources))]
	public String   EmailAddress { get; set; }
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[LocalizedDisplayName("PHONE", NameResourceType=typeof(CustomerResources))]
	public String   Phone { get; set; }
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_PASSWORDHASH_REQUIRED", ErrorMessageResourceType=typeof(CustomerResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("PASSWORDHASH", NameResourceType=typeof(CustomerResources))]
	public String   PasswordHash { get; set; }
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_PASSWORDSALT_REQUIRED", ErrorMessageResourceType=typeof(CustomerResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("PASSWORDSALT", NameResourceType=typeof(CustomerResources))]
	public String   PasswordSalt { get; set; }
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[SystemProperty()]
	[LocalizedDisplayName("ROWGUID", NameResourceType=typeof(CustomerResources))]
	public Guid   rowguid { get; set; }
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_MODIFIEDDATE_REQUIRED", ErrorMessageResourceType=typeof(CustomerResources))]
		
	[RelationFilterable()]
	[DateTime(true, false, null)]	
	[LocalizedDisplayName("MODIFIEDDATE", NameResourceType=typeof(CustomerResources))]
	public DateTime   ModifiedDate { get; set; }
	public string ModifiedDateText {
        get {
            if (ModifiedDate != null)
			
                return ((DateTime)ModifiedDate).ToShortDateString();
            else
                return String.Empty;
        }
				set{
				this.ModifiedDate = Convert.ToDateTime(value);
    }
		}
		
		
		
		[LocalizedDisplayName("CUSTOMERADDRESSES", NameResourceType=typeof(CustomerResources))]
		[RelationFilterable(IsNavigationPropertyMany=true, FiltrablePropertyPathName="CustomerAddresses.Count()", ModelPartialType="CustomerAddresses.CustomerAddress")]
        public List<CustomerAddresses.CustomerAddressModel> CustomerAddresses { get; set; }			
	
		[LocalizedDisplayName("SALESORDERHEADERS", NameResourceType=typeof(CustomerResources))]
		[RelationFilterable(IsNavigationPropertyMany=true, FiltrablePropertyPathName="SalesOrderHeaders.Count()", ModelPartialType="SalesOrderHeaders.SalesOrderHeader")]
        public List<SalesOrderHeaders.SalesOrderHeaderModel> SalesOrderHeaders { get; set; }			
	
	public override string SafeKey
   	{
		get
        {
			if(this.CustomerID != null)
				return SFSdotNet.Framework.Entities.Utils.GetKey(this ,"CustomerID").Replace("/","-");
			else
				return String.Empty;
		}
    }		
		public void Bind(CustomerModel model){
            
		this.CustomerID = model.CustomerID;
		this.NameStyle = model.NameStyle;
		this.Title = model.Title;
		this.FirstName = model.FirstName;
		this.MiddleName = model.MiddleName;
		this.LastName = model.LastName;
		this.Suffix = model.Suffix;
		this.CompanyName = model.CompanyName;
		this.SalesPerson = model.SalesPerson;
		this.EmailAddress = model.EmailAddress;
		this.Phone = model.Phone;
		this.PasswordHash = model.PasswordHash;
		this.PasswordSalt = model.PasswordSalt;
		this.rowguid = model.rowguid;
		this.ModifiedDate = model.ModifiedDate;
        }

        public BusinessObjects.Customer GetBusinessObject()
        {
            BusinessObjects.Customer result = new BusinessObjects.Customer();
	if (this.CustomerID != null )
				result.CustomerID = (Int32)this.CustomerID;
				
	if (this.NameStyle != null )
				result.NameStyle = (Boolean)this.NameStyle;
				
	if (this.Title != null )
				result.Title = (String)this.Title.Trim().Replace("\t", String.Empty);
				
	if (this.FirstName != null )
				result.FirstName = (String)this.FirstName.Trim().Replace("\t", String.Empty);
				
	if (this.MiddleName != null )
				result.MiddleName = (String)this.MiddleName.Trim().Replace("\t", String.Empty);
				
	if (this.LastName != null )
				result.LastName = (String)this.LastName.Trim().Replace("\t", String.Empty);
				
	if (this.Suffix != null )
				result.Suffix = (String)this.Suffix.Trim().Replace("\t", String.Empty);
				
	if (this.CompanyName != null )
				result.CompanyName = (String)this.CompanyName.Trim().Replace("\t", String.Empty);
				
	if (this.SalesPerson != null )
				result.SalesPerson = (String)this.SalesPerson.Trim().Replace("\t", String.Empty);
				
	if (this.EmailAddress != null )
				result.EmailAddress = (String)this.EmailAddress.Trim().Replace("\t", String.Empty);
				
	if (this.Phone != null )
				result.Phone = (String)this.Phone.Trim().Replace("\t", String.Empty);
				
	if (this.PasswordHash != null )
				result.PasswordHash = (String)this.PasswordHash.Trim().Replace("\t", String.Empty);
				
	if (this.PasswordSalt != null )
				result.PasswordSalt = (String)this.PasswordSalt.Trim().Replace("\t", String.Empty);
				
	if (this.rowguid != null )
				result.rowguid = (Guid)this.rowguid;
				
				result.ModifiedDate = (DateTime)this.ModifiedDate;		
				



            return result;
        }
        public void Bind(BusinessObjects.Customer businessObject)
        {
            
			this.CustomerID = businessObject.CustomerID;
				
			this.NameStyle = businessObject.NameStyle;
				
				
	if (businessObject.Title != null )
				this.Title = (String)businessObject.Title;
			this.FirstName = businessObject.FirstName != null ? businessObject.FirstName.Trim().Replace("\t", String.Empty) : "";
				
				
	if (businessObject.MiddleName != null )
				this.MiddleName = (String)businessObject.MiddleName;
			this.LastName = businessObject.LastName != null ? businessObject.LastName.Trim().Replace("\t", String.Empty) : "";
				
				
	if (businessObject.Suffix != null )
				this.Suffix = (String)businessObject.Suffix;
				
	if (businessObject.CompanyName != null )
				this.CompanyName = (String)businessObject.CompanyName;
				
	if (businessObject.SalesPerson != null )
				this.SalesPerson = (String)businessObject.SalesPerson;
				
	if (businessObject.EmailAddress != null )
				this.EmailAddress = (String)businessObject.EmailAddress;
				
	if (businessObject.Phone != null )
				this.Phone = (String)businessObject.Phone;
			this.PasswordHash = businessObject.PasswordHash != null ? businessObject.PasswordHash.Trim().Replace("\t", String.Empty) : "";
				
			this.PasswordSalt = businessObject.PasswordSalt != null ? businessObject.PasswordSalt.Trim().Replace("\t", String.Empty) : "";
				
			this.rowguid = businessObject.rowguid;
				
				this.ModifiedDate = (DateTime)businessObject.ModifiedDate;
           
        }
	}
}
